package com.lost.octopus.es.processor.util;

import com.sunsharing.share.boot.framework.code.CodeLoader;

import org.springframework.context.ApplicationContext;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * spring全局静态实例操作工具
 * @author zhangbh
 **/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ApplicationUtil {
    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        ApplicationUtil.applicationContext = applicationContext;
    }

    public static String transDm(String alias, String value) {
        CodeLoader bean = ApplicationUtil.applicationContext.getBean(CodeLoader.class);
        return bean.getCodeStrToZw(value, alias);
    }

    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }
}
